package br.com.oo.app;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.util.PDFMergerUtility;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws COSVisitorException, IOException
    {
    	System.out.println("Iniciando merge de PDFs ");
    	PDFMergerUtility mergePdf = new PDFMergerUtility();

    	mergePdf.addSources(getPdfs());

    	mergePdf.setDestinationFileName("C:\\temp\\pdf\\pdfMerge.pdf");
    	System.out.println("Verifique o arquivo: 'C:\\temp\\pdf\\pdfMerge.pdf'");

    	mergePdf.mergeDocuments();
    }
    
    public static List< InputStream > getPdfs() throws FileNotFoundException {
    	List< InputStream > pdfs = new ArrayList<InputStream>();
    	
    	FileInputStream pdf1 = new FileInputStream("C:\\temp\\pdf\\pdf1.pdf");
    	System.out.println("Lendo PDF: 'C:\\temp\\pdf\\pdf1.pdf'");
    	
    	FileInputStream pdf2 = new FileInputStream("C:\\temp\\pdf\\pdf2.pdf");
    	System.out.println("Lendo PDF: 'C:\\temp\\pdf\\pdf2.pdf'");
    	
    	FileInputStream pdf3 = new FileInputStream("C:\\temp\\pdf\\pdf3.pdf");
    	System.out.println("Lendo PDF: 'C:\\temp\\pdf\\pdf3.pdf'");
    	
    	pdfs.add(pdf1);
    	pdfs.add(pdf2);
    	pdfs.add(pdf3);
    	
    	return pdfs;
    }
}
